<?php
require_once('lanceur_spip.php');
include_spip('functions/pdk_common');
require_once(_DIR_PLUGIN_PDK.'classes/simpletest/class.PdkTest.php');

/**
 *  AlohacartPaymentInterkassa class test case
 */
class TestClassAlohacartPaymentInterkassa extends PdkTest {
    /**
     *  AlohacartPaymentInterkassa
     */
    private $payment;
    
    function __construct(){
        parent::__construct();
        
        $this->payment = pdk_load_class('AlohacartPaymentInterkassa', 'classes/payment');
		
		$this->dropTestTables = TESTS_DROP_TEST_TABLES;
    }
        
    /**
     *  Run before each test
     */
    function setUp() {
        parent::setUp();
    }
    
    /**
     *  Run after each test
     */
    function tearDown() {
        parent::tearDown();
    }
    
    function __destruct() {
        parent::__destruct();
    }
    
    function Test_CheckHash() {
        $status_data = array();
        $status_data['ik_shop_id'] = '48CCB334-746D-CB34-840D-AB477D137079';
        $status_data['ik_payment_amount'] = '9999';
        $status_data['ik_payment_id'] = '12';
        $status_data['ik_paysystem_alias'] = 'webmoneyu';
        $status_data['ik_baggage_fields'] = 'email: mail@mail.com, tel: +380441234567';
        $status_data['ik_payment_state'] = 'success';
        $status_data['ik_trans_id'] = 'IK_68';
        $status_data['ik_currency_exch'] = '1';
        $status_data['ik_fees_payer'] = '0';
        
        $meta_data = $this->payment->GetMetaData();
        $secret_key = $meta_data['secret_key'];
        
        $sing_hash_str = $status_data['ik_shop_id'].':'.
            $status_data['ik_payment_amount'].':'.
			$status_data['ik_payment_id'].':'.
			$status_data['ik_paysystem_alias'].':'.
			$status_data['ik_baggage_fields'].':'.
			$status_data['ik_payment_state'].':'.
			$status_data['ik_trans_id'].':'.
			$status_data['ik_currency_exch'].':'.
			$status_data['ik_fees_payer'].':'.
			$secret_key;
        
        $sign_hash = strtoupper(md5($sing_hash_str));        
        $status_data['ik_sign_hash'] = $sign_hash;
        
        $this->assertTrue($this->payment->CheckHash($status_data));
    }
    
  
}